<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>文本域</title>
</head>

<body>
  <textarea name="" id="" cols="30" rows="10"></textarea>
  <script>
    const tx = document.querySelector('textarea')
    tx.addEventListener('keyup', function (e) {
      if (e.key === 'Enter') {
        console.log(tx.value);
        // 获取内容并且清空输入框两侧的空格
        console.log(tx.value.trim());
      }
    })
  </script>
</body>

</html>